package com.snake.excel2java.excel.common.ext.file;

import com.snake.excel2java.excel.common.ext.row.GroupRowExt;
import com.snake.excel2java.excel.common.file.Group;

import com.snake.excel2java.excel.type.ShoprankType;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
@NoArgsConstructor
public class GroupExt extends Group {

	HashMap<Integer, List<GroupRowExt>> groupMap = null;

	HashMap<Integer, List<GroupRowExt>> hitMap10 = null;

	HashMap<Integer, List<Integer>> shopIdGroupMap = null;

	// 添加其他的功能
	protected void parse() {

		List<GroupRowExt> list = null;
		List<GroupRowExt> hitList10 = null;
		HashMap<Integer, List<GroupRowExt>> groupMap = new HashMap<>();
		HashMap<Integer, List<GroupRowExt>> hitMap10 = new HashMap<>();
		HashMap<Integer, List<Integer>> shopIdGroupMap = new HashMap<>();

		for(Map.Entry<Integer, GroupRowExt> entry: getDataMap().entrySet()) {

			GroupRowExt rowExt = entry.getValue();

			int groupId = rowExt.getGroupId();

            list = groupMap.computeIfAbsent(groupId, k -> new LinkedList<>());
            list.add(rowExt);

			// 10次必中
			if(rowExt.getRank() == ShoprankType.epic.getValue()) {
                hitList10 = hitMap10.computeIfAbsent(groupId, k -> new LinkedList<>());
                hitList10.add(rowExt);
			}

			List<Integer> shopIdList = shopIdGroupMap.get(rowExt.getGroupId());
			if(null == shopIdList) {
				shopIdList = new LinkedList<>();
				shopIdGroupMap.put(rowExt.getGroupId(), shopIdList);
			}

			shopIdList.add(rowExt.getShopId());

		}

		this.groupMap = groupMap;
		this.hitMap10 = hitMap10;
		this.shopIdGroupMap = shopIdGroupMap;
	}

	public List<GroupRowExt> getListByGroupId(int groupId) {
		return groupMap.get(groupId);
	}

	public List<GroupRowExt> getHit10ListByGroupId(int groupId) {
		return hitMap10.get(groupId);
	}

//	public

}